/*
 * @Author: your name
 * @Date: 2021-09-28 13:34:41
 * @LastEditTime: 2021-10-21 11:51:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue_demo\src\store\index.js
 */
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'

Vue.use(Vuex)

// https://webpack.js.org/guides/dependency-management/#requirecontext
const modulesFiles = require.context('./modules', true, /\.js$/)

// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
    // set './app.js' => 'app'
    const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
    const value = modulesFiles(modulePath)
    modules[moduleName] = value.default
    return modules
}, {})

const store = new Vuex.Store({
    modules,
    getters
})

export default store

// import Vue from 'vue'
// import Vuex from 'vuex'

// Vue.use(Vuex)

// export default new Vuex.Store({
//     state: {
//         // 确定弹出框是否弹出
//         showState: false,
//         // 点击的是否是左边菜单栏或者左上角退出按钮
//         showItem: false,
//         // 跳转路径
//         toPath: ''

//     },
//     mutations: {
//         setShowState(state, value) {
//             console.log(value)
//             state.showState = value
//         },
//         setShowItem(state, value) {
//             console.log(value)
//             state.showItem = value
//         },
//         setToPath(state, value) {
//             console.log(value)
//             state.toPath = value
//         }
//     },
//     actions: {},
//     modules: {}
// })
